package top.tangyh.lamp.care.vo.result;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;


public class PageOutputDTO<T> implements Serializable {
    private Long total;
    private Long page;
    private Long current;
    private List<T> list;

    public static <C> PageOutputDTO<C> buildPageOutput(PageInfo<C> pageInfo) {
        PageOutputDTO<C> pageOutputDTO = new PageOutputDTO();
        pageOutputDTO.setList(pageInfo.getList());
        pageOutputDTO.setTotal(pageInfo.getTotal());
        pageOutputDTO.setPage((long)pageInfo.getPages());
        pageOutputDTO.setCurrent((long)pageInfo.getPageNum());
        return pageOutputDTO;
    }

    public static long getTotalPage(long total, long pageSize) {
        return (total + pageSize - 1L) / pageSize;
    }

    public Long getTotal() {
        return this.total;
    }

    public Long getPage() {
        return this.page;
    }

    public Long getCurrent() {
        return this.current;
    }

    public List<T> getList() {
        return this.list;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public void setCurrent(Long current) {
        this.current = current;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof PageOutputDTO)) {
            return false;
        } else {
            PageOutputDTO<?> other = (PageOutputDTO)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$total = this.getTotal();
                    Object other$total = other.getTotal();
                    if (this$total == null) {
                        if (other$total == null) {
                            break label59;
                        }
                    } else if (this$total.equals(other$total)) {
                        break label59;
                    }

                    return false;
                }

                Object this$page = this.getPage();
                Object other$page = other.getPage();
                if (this$page == null) {
                    if (other$page != null) {
                        return false;
                    }
                } else if (!this$page.equals(other$page)) {
                    return false;
                }

                Object this$current = this.getCurrent();
                Object other$current = other.getCurrent();
                if (this$current == null) {
                    if (other$current != null) {
                        return false;
                    }
                } else if (!this$current.equals(other$current)) {
                    return false;
                }

                Object this$list = this.getList();
                Object other$list = other.getList();
                if (this$list == null) {
                    if (other$list != null) {
                        return false;
                    }
                } else if (!this$list.equals(other$list)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof PageOutputDTO;
    }


    public String toString() {
        return "PageOutputDTO(total=" + this.getTotal() + ", page=" + this.getPage() + ", current=" + this.getCurrent() + ", list=" + this.getList() + ")";
    }

    public static <T> Page<T> listToPage(List<T> src){
        Page<T> resultList = new Page();
        for(T item:src){
            resultList.add(item);
        }
        resultList.setPages(1);
        resultList.setPageSize(src.size());
        resultList.setPageNum(1);
        return  resultList;
    }

    public static <T> PageInfo<T> newPageInfo(List<T> list){
        PageInfo pageInfo =new PageInfo(list);
        pageInfo.setPageNum(1);
        pageInfo.setTotal(list.size());
        pageInfo.setSize(list.size());
        return  pageInfo;
    }


    public PageOutputDTO(Long total, Long page, Long current, List<T> list) {
        this.total = total;
        this.page = page;
        this.current = current;
        this.list = list;
    }

    public PageOutputDTO() {
    }
}
